package com.media.themovieworld.util;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.media.themovieworld.MovieWorldApp;

public class AppSettingPrefference {

	private final String PREF_NAME	= "movie_world_pref";
	private final int PRIVATE_MODE = 0;
	
	public static final String FACEBOOK_ID_KEY = "facebook_id_key";
	
	public static final String MOVIE_QUALITY_KEY = "movie_quality";
	public static final String MOVIE_CHROMA_KEY	 = "movie_chroma";
	public static final String MOVIE_LANGUAGE_KEY = "language_key";
	
	private static AppSettingPrefference INSTANCE = null;
	private SharedPreferences mSharedPreferences;
	private SharedPreferences.Editor mEditor;
	
	public static AppSettingPrefference getInstance(){
		if (INSTANCE == null) {
			INSTANCE = new AppSettingPrefference();
		}
		return INSTANCE;
	}
	
	private SharedPreferences getSharePref(){
		if (mSharedPreferences == null) {
			mSharedPreferences = MovieWorldApp.APP_CONTEXT.getSharedPreferences(PREF_NAME,PRIVATE_MODE);
		}
		return mSharedPreferences;
	}
	
	private Editor getPrefEditor(){
		if (mEditor == null) {
			mEditor = getSharePref().edit();
		}
		return mEditor;
	}
	
	public String getMovieQuality(){
		String ret = getSharePref().getString(MOVIE_QUALITY_KEY, "");
		return ret;
	}
	
	public String getMovieChroma(){
		String ret = getSharePref().getString(MOVIE_CHROMA_KEY, "");
		return ret;
	}
	
	public void setMovieQuality(String quality){
		Editor editor = getPrefEditor();
		if (quality!=null) {
			editor.putString(MOVIE_QUALITY_KEY, quality);
			editor.commit();
		}
	}
	
	public void setMovieChroma(String chroma){
		Editor editor = getPrefEditor();
		if (chroma!=null) {
			editor.putString(MOVIE_CHROMA_KEY, chroma);
			editor.commit();
		}
	}
	
	public void setMovieLanguage(String language){
		Editor editor = getPrefEditor();
		if (language!=null) {
			editor.putString(MOVIE_LANGUAGE_KEY, language);
			editor.commit();
		}
	}
	
	public String getMovieLanguage(){
		String ret = getSharePref().getString(MOVIE_LANGUAGE_KEY, "en");
		return ret;
	}
	
	public void setFacebookId(String id){
		Editor editor = getPrefEditor();
		if (id!=null) {
			editor.putString(FACEBOOK_ID_KEY, id);
			editor.commit();
		}
	}
	
	public String getFacebookId(){
		String ret = getSharePref().getString(FACEBOOK_ID_KEY, "");
		return ret;
	}
	
}
